package com.rzwl.single.server.entity;

import com.alibaba.fastjson.JSONObject;
import io.swagger.models.auth.In;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.annotation.CreatedDate;

import javax.persistence.Basic;
import java.net.URLEncoder;
import java.sql.Timestamp;
import java.util.Arrays;

/**
 * @author : championjing
 * @ClassName: ScoreVO
 * @Description: TODO
 * @Date: 2020-08-02 19:38
 */
@Slf4j
@Data
public class ScoreVO {

    private Long id;
    private String openid;
    private Integer over;
    private TeamScore lef;
    private TeamScore righ;
    private Timestamp ctime;
    
    public Score transfer() {
        Score score = new Score();
        
        score.setId( this.getId() );
        score.setOpenid( this.getOpenid());
        score.setOver( this.getOver() == null?0:this.getOver() );
        score.setLef(this.getLef().toString() );
        score.setRigh( this.getRigh().toString() );
        score.setCtime( this.getCtime() );
        if ( score.getCtime() == null ) {
            score.setCtime( new Timestamp(System.currentTimeMillis()) );
        }
        log.info("res:{}", JSONObject.toJSONString(score) );
        
        return score;
    }
}

@Data
class TeamScore {
    private Integer score;
    private Integer[] balls;
    private Integer skip;

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("{score:");
        sb.append( this.getScore() );
        sb.append( "," );
        sb.append( "balls:");
        sb.append( Arrays.toString( this.getBalls() ) );
        sb.append( "," );
        sb.append("skip:");
        sb.append( this.getSkip() );
        sb.append( "}" );
        return sb.toString();
    }
}
